home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.0 / Video Toaster v4.0.iso / programs / flyercalibrate < prev    next >
Text File  |  1995-02-28  |  12KB  |  495 lines

  1. /* Flyer Auto-Calibration, Version 17-Dec-94, by SKell, NewTek Inc. */
  2.  
  3. OPTIONS RESULTS
  4. numeric digits 12
  5.  
  6. /*-------------------------------------------------*/
  7. /* You may need to adjust these "assigns" for your system" */
  8.  
  9. TOAST = ""
  10. FLYER = "Flyer_Support/C/"
  11.  
  12. /*-------------------------------------------------*/
  13. /* Lets make sure they're not installed yet.       */
  14. remlib("ToasterARexx.port")
  15. remlib("rexxmathlib.library")
  16.  
  17. say "Flyer Auto-Calibration, Version 17-Dec-94"
  18. say
  19. say "This script must be in your Programs drawer."
  20. say
  21. say "Requires the following Flyer utilities:"
  22. say FLYER'PlayClip'
  23. say FLYER'SetFloobyCal'
  24. say FLYER'CalibNew'
  25. say FLYER'SetPlayMode'
  26. say
  27.  
  28. address command
  29. 'cd >nil: 'TOAST
  30. address
  31.  
  32. TestClip=""
  33.  
  34. /*------------------------------------------*/
  35. if pos("ToasterARexx.port" , show('Ports'))=0 then do
  36.  
  37. say
  38. say "Please wait for the Switcher to load."
  39.  
  40. address command
  41. 'run >nil: VideoToaster'
  42. address
  43.  
  44. /* Wait for the Switcher to come up */
  45.  
  46.    waitcount=0
  47.    do while pos("ToasterARexx.port" , show('Ports'))=0
  48.  
  49. address command
  50. 'wait 1'
  51. address
  52.  
  53.       waitcount = waitcount+1
  54.  
  55.       if(waitcount > 40) then do
  56.          say "The Switcher Failed to Load!"
  57.          say "Maybe you want to try again?"
  58.          exit
  59.       end
  60.    end
  61. end
  62.  
  63. addlib("ToasterARexx.port" , 0)
  64. SWITCHER(TOWB)
  65.  
  66. /* The Switcher is now up and running */
  67. /*------------------------------------------*/
  68.  
  69. /* calibrate the genlock */
  70.  
  71. say "Calibrating the Flyer Genlock."
  72.  
  73. address command
  74. FLYER'calibnew >nil: GC'
  75. 'c:wait 2'
  76. FLYER'SetFloobyCal >nil: 0 10 0 0'    /* reset some stuff in the Flyer */        
  77. address
  78.  
  79. open(in,"ENV:CalibResult",'read')
  80. instring = readln(in)
  81. close(in)
  82. parse value instring with result
  83.  
  84. if (result ~= 0.0)  then do
  85.    say "Problem detected during Genlock calibration."
  86.     say "Error #"result
  87.     say "Please power down, and then try again."
  88.     GetOutaHere("If the problem persists, contact NewTek for help.")
  89. end
  90.  
  91. /*------------------------------------------*/
  92.  
  93. /* See if an existing TestSignal clip exists. If so, use it. */
  94. count=0
  95. volume=1
  96. do until((TestClip ~= "") | (volume=""))
  97.     volume=SWITCHER(FLYV,count,1)        /* see what Flyer Video volumes exist */
  98.     count=count+1
  99.  
  100.     if(volume ~= "") then do
  101.         clipname=value("volume")':TestSignal'
  102.         if(exists(clipname)) then TestClip=clipname
  103.     end
  104. end
  105.  
  106. if(TestClip = "") then do
  107.     say "Creating a Flyer Test Clip"
  108.  
  109.     TestClip=SWITCHER(FLY1)        /* create a test clip */
  110.  
  111.     if(TestClip="") then do
  112.         say "Unable to create a Test Clip on one of your Flyer drives."
  113.         say "If your Video drives are full,"
  114.         say " you may need to free up some space."
  115.         say "You may want to power down, and then try again."
  116.         GetOutaHere("If the problem persists, contact NewTek for help.")
  117.     end
  118.  
  119.     say "Created "TestClip" test clip."
  120. end
  121.  
  122. /**********************************/
  123.  
  124. address command
  125. FLYER'playclip >nil: 0 0 0 'TestClip' 0 0 0 1 0'
  126. address
  127.  
  128. SWITCHER(TOSW)
  129. SWITCHER(M003)
  130. SWITCHER(P003)
  131.  
  132. if(ConnectLoopBack()=FALSE) then do
  133.  
  134.     /* see if the user ever did any autohue */
  135.     if(SWITCHER(STAT,DHUE) < 0) then do
  136.         /* The user has never AutoHued their Toaster, so set Digital Phase */
  137.     
  138.         say "Calibrating the Toasters digital phase."  
  139.         best=CaliDigitalPhase()
  140.         SWITCHER(DHUE,best+256)
  141.           SWITCHER(MKHS)
  142.     end
  143.     else do
  144.         /* is the current Digital Phase Error > 3 degrees = (65536*sine(error)) ?*/
  145.         if(abs(SWITCHER(DH3E)) > 3430) then do
  146.             SWITCHER(TOWB)
  147.             say "Do you have a video source connected to input 1 of your Toaster (Y/N)?"
  148.             pull myhair
  149.             if (left(myhair,1) ~= "N") then do
  150.                 say "Your Toaster may need AutoHueing."
  151.                 say "You should Quit this script, AutoHue the Toaster,"
  152.                 say "and then run this script again."
  153.                 say "Do you want to continue this script anyway (Y/N)?"
  154.                 pull myhair
  155.                 if (left(myhair,1) ~= "Y") then do
  156.                     SWITCHER(TOSW)
  157.                     SWITCHER(NOIQ)
  158.                     SWITCHER(TOWB)
  159.                     remlib("ToasterARexx.port")
  160.                     exit
  161.                 end
  162.                 else do
  163.                     say "WARNING!"
  164.                     say "Because you have chosen to skip Toaster AutoHueing,"
  165.                     say "your Flyers playback hue may not be calculated accurately."
  166.                 end
  167.             end
  168.         
  169.             say "Is it OK for me to adjust your Toaster Digital Hue (Y/N)?"
  170.             pull myhair
  171.             SWITCHER(TOSW)
  172.  
  173.             if (left(myhair,1) ~= "N") then do
  174.                 say "Calibrating the Toasters digital phase."  
  175.                 best=CaliDigitalPhase()
  176.                 SWITCHER(DHUE,best)
  177.                 SWITCHER(MKHS)
  178.             end
  179.         end
  180.     end
  181.  
  182.     DigitalPhaseError = DeltaHue2Angle(SWITCHER(DH3E))
  183.  
  184.     if(abs(DigitalPhaseError) > 5) then do
  185.         SWITCHER(TOWB)
  186.         say "Your Toaster has a Digital Hue error of "DigitalPhaseError" degrees."
  187.         say "So, the Flyer's playback phase may not be calibrated correctly!"
  188.         say "You should try AutoHueing your Toaster, and then repeat this script."
  189.         SWITCHER(TOSW)
  190.     end
  191. end
  192.  
  193. /*------------------------------------------*/
  194.  
  195. say "Please wait. Calibrating the Flyer Record Phase."
  196.  
  197. SWITCHER(MDV2)
  198. SWITCHER(PDV1)    /* tell it to load into DV1        */
  199. SWITCHER(PAT1) /* Generatate test signal into DV1 */
  200. SWITCHER(MDV1)
  201. SWITCHER(PDV1)
  202. SWITCHER(TOWB)
  203.  
  204.  
  205. /*******************/
  206. /* Auto Record Hue */
  207. address command
  208. FLYER'CalibNew >nil: AR 2'
  209. FLYER'SetPlayMode 0 PLAY'
  210. address
  211.  
  212. open(in,"ENV:CalibResult",'read')
  213. instring = readln(in)
  214. close(in)
  215. parse value instring with RecordPhaseError
  216.  
  217. /* check for number of degrees error */
  218. if (abs(RecordPhaseError) > 3) then do
  219.    say "Problem detected during Flyer Record Phase calibration."
  220.     say "Record Phase error ="RecordPhaseError" degrees."
  221.     say "Please power down, and then try again."
  222.     GetOutaHere("If the problem persists, contact NewTek for help.")
  223. end
  224. /******************/
  225.  
  226. /*------------------------------------------*/
  227. SWITCHER(TOSW)
  228.  
  229. say "Calibrating the Flyers Playback Phase on channel 0."  
  230. Play0PhaseError=CalibratePlay(0)
  231.  
  232. say "Calibrating the Flyers Playback Phase on channel 1."  
  233. Play1PhaseError=CalibratePlay(1)
  234.  
  235. address command
  236. 'echo >ENV:FlyerCalibResults 'DigitalPhaseError RecordPhaseError Play0PhaseError Play1PhaseError
  237. /* 'type ENV:FlyerCalibResults' */
  238. address
  239.  
  240. GetOutaHere("Flyer Calibration was successful.")
  241. exit
  242.  
  243.  
  244. /******************************************************************/
  245. /******************************************************************/
  246. CalibratePlay:
  247.     arg    VidChannel
  248.  
  249. if(VidChannel=0) then do
  250.     SWITCHER(M003)
  251.     SWITCHER(P003)
  252.     grab=IQ30
  253. end
  254. else do
  255.     SWITCHER(M004)
  256.     SWITCHER(P004)
  257.     grab=IQ40
  258. end
  259.  
  260. /*-----------*/
  261. address command
  262. 'c:copy >nil: 'FLYER'SetFloobyCal RAM: quiet'
  263. FLYER'playclip >nil: 0 'VidChannel' 0 'TestClip' 0 0 0 1 0'
  264. 'RAM:SetFloobyCal >nil: 'VidChannel' 2 0 0 0 0'        
  265. address
  266. /*-----------*/
  267.  
  268. result=SWITCHER(value(grab))
  269. parse value result with 1 YPI +4 YPQ +4 YNI +4 YNQ +4
  270. I0= c2d(YPI)-c2d(YNI)
  271. Q0= c2d(YPQ)-c2d(YNQ)
  272. Ivect=I0/324
  273. Qvect=Q0/324
  274. saturation=squareroot((Ivect*Ivect)+(Qvect*Qvect))
  275.  
  276. /* check for at least 20 digital units of saturation (ideal=64) */
  277. if(saturation < 20) then do
  278.     satpercent =(saturation*100)/64 
  279.     say "Flyer clip is playing with insufficient saturation."
  280.     say "Saturation ="satpercent" percent"
  281.     say "You may want to power down, and then try again."
  282.     GetOutaHere("If the problem persists, contact NewTek for help.")
  283. end
  284.  
  285. /*----------*/
  286. SWITCHER(DIIM)        /* disable imagery */
  287.  
  288. QabsBest= 500000000    /* bogus initial value */
  289. Position=-35
  290.  
  291. do until ((PlayPhaseError < 3) | (Position=0))
  292.     if(Position=-34) then posit="ffde"
  293.     else if(Position=-35) then posit="ffdd"
  294.     else if(Position=-36) then posit="ffdc" 
  295.  
  296.     /* set play position  */
  297.     address command
  298.     'RAM:SetFloobyCal >nil: 'VidChannel' 5 0 'posit
  299.     address
  300.  
  301.     do clock=0 to 3  
  302.         do    coarse=0 to 9
  303.             do fine=0 to 7
  304.                 address command
  305.                 'RAM:SetFloobyCal >nil: 'VidChannel' 2 0 'clock coarse fine        
  306.                 address
  307.  
  308.                 result=SWITCHER(value(grab))
  309.                 parse value result with 1 YPI +4 YPQ +4 YNI +4 YNQ +4
  310.                 I0= c2d(YPI)-c2d(YNI)
  311.                 Q0= c2d(YPQ)-c2d(YNQ)
  312.                 Qabs = abs(Q0)
  313.  
  314.                 if((Qabs < QabsBest) & (I0 > 0)) then do
  315.                     PositionBest=Position
  316.                     positBest=posit
  317.                     Ibest=I0
  318.                     Qbest=Q0
  319.                     QabsBest=Qabs
  320.                     ClockBest=clock
  321.                     CoarseBest=coarse
  322.                     FineBest=fine
  323.                 end
  324.             end fine
  325.         end coarse
  326.     end clock
  327.  
  328.     if(Position=-35) then Position=-34
  329.     else if(Position=-34) then Position=-36
  330.     else if(Position=-36) then Position=0
  331.  
  332.     PlayPhaseError = IQ2Hue(Ibest,Qbest)
  333. end
  334.     
  335. SWITCHER(ENIM)        /* enable imagery */
  336.  
  337. /* say "Clock Coarse Fine ="PositionBest ClockBest CoarseBest FineBest */
  338.  
  339. if(abs(PlayPhaseError) > 3) then do
  340.    say "Problem detected during Flyer Play Phase calibration."
  341.     say "Play Phase error ="PlayPhaseError" degrees."
  342.     say "Please power down, and then try again."
  343.     GetOutaHere("If the problem persists, contact NewTek for help.")
  344. end
  345.  
  346. /* save it in non-volatile memory */
  347. address command
  348. 'RAM:SetFloobyCal >nil: 'VidChannel' 5 1 'positBest
  349. 'RAM:SetFloobyCal >nil: 'VidChannel' 2 1 'ClockBest CoarseBest FineBest
  350. 'c:delete >nil: RAM:SetFloobyCal quiet'
  351. address
  352.  
  353. return (PlayPhaseError)
  354.  
  355. /******************************************************************/
  356. /******************************************************************/
  357. ConnectLoopBack:
  358.     abort=FALSE
  359.     SWITCHER(TOSW)
  360.  
  361.     do while((abort=FALSE) & (SWITCHER(STAT,V2IS) = 0)) 
  362.         SWITCHER(TOWB)
  363.         say "Please connect the output of your Toaster to the Toasters Input 2."
  364.         say "Please press <RETURN> when ready. (or enter 'A' to abort)"
  365.         pull myhair
  366.  
  367.         if (left(myhair,1) = "A") then do
  368.             abort=TRUE
  369.             say "WARNING!"
  370.             say "Toaster Digital Hue adjustment has been aborted."
  371.             say "Your Flyer's playback phase may not be calibrated correctly!"
  372.         end
  373.  
  374.         SWITCHER(TOSW)
  375.     end
  376. return(abort)
  377.  
  378. /******************************************************************/
  379. /******************************************************************/
  380. CaliDigitalPhase:
  381.  
  382. abserr=130000    /* bogus error */
  383.  
  384. do dp=0 to 63
  385.     SWITCHER(DHUE,dp)
  386. /*    SWITCHER(M003) */
  387.     dperr=SWITCHER(DH3E)            /* signed error */
  388.     absdp=abs(dperr)
  389.  
  390.     if(absdp < abserr) then do
  391.         error=dperr
  392.         abserr=absdp
  393.         best=dp
  394.     end
  395. end
  396.  
  397. /* say "BestDP="best" Error="error */
  398.  
  399. return(best)
  400.  
  401. /******************************************************************/
  402. /******************************************************************/
  403. /* -180 < result < 180 degrees */
  404. polar: procedure
  405.     arg    opposite,adjacent
  406.  
  407.     if adjacent = 0 then do
  408.         if opposite < 0 then return 270
  409.             else return 90
  410.         end 
  411.     
  412.     remlib("ToasterARexx.port")
  413.     addlib("rexxmathlib.library",0,-30,0)
  414.     result = 57.29578*atan(opposite/adjacent)
  415.     remlib("rexxmathlib.library")
  416.     addlib("ToasterARexx.port",0)
  417.  
  418.     if adjacent < 0 then result = result + 180
  419. return    result
  420.  
  421. /******************************************************************/
  422. /******************************************************************/
  423. IQ2Hue: procedure
  424.     arg ip,qp
  425.     
  426.     hue = polar(-qp,ip)    /* return degrees from I vector */
  427. return hue
  428.  
  429. /******************************************************************/
  430. /******************************************************************/
  431. DeltaHue2Angle: procedure
  432.     arg    foo
  433.  
  434.     foo = foo/65536
  435.     if (( foo > 1.0 ) | (foo < -1.0)) then result = 3.1416*sign(foo) + arcsine(foo-2*sign(foo))
  436.     else result = arcsine(foo)
  437. return 57.29578*result
  438.  
  439. /******************************************************************/
  440. squareroot: procedure
  441.     arg    param
  442.  
  443.     remlib("ToasterARexx.port")
  444.     addlib("rexxmathlib.library",0,-30,0)
  445.     result = sqrt(param)
  446.     remlib("rexxmathlib.library")
  447.     addlib("ToasterARexx.port",0)
  448. return    result
  449.  
  450. /******************************************************************/
  451. arcsine: procedure
  452.     arg    param
  453.  
  454.     remlib("ToasterARexx.port")
  455.     addlib("rexxmathlib.library",0,-30,0)
  456.     result = asin(param)
  457.     remlib("rexxmathlib.library")
  458.     addlib("ToasterARexx.port",0)
  459. return    result
  460.  
  461.  
  462. /******************************************************************/
  463. /******************************************************************/
  464.  
  465. GetOutaHere:
  466.     parse arg message
  467.  
  468.     SWITCHER(TOSW)
  469.     SWITCHER(NOIQ)
  470.     SWITCHER(TOWB)
  471.  
  472.     say message
  473.  
  474. /**********
  475.     if(TestClip ~= "") then do
  476.         say "Would you like me to delete the "TestClip" clip (Y/N)?"
  477.         pull myhair
  478.         if (left(myhair,1) ~= "N") then do
  479. address command
  480. 'c:delete >nil: 'TestClip' quiet'
  481. address
  482.         end
  483.     end    
  484.     else do
  485.         say "Press <RETURN> to exit."
  486.         pull myhair
  487.     end
  488. **********/
  489.     say "Press <RETURN> to exit."
  490.     pull myhair
  491.  
  492.     remlib("ToasterARexx.port")
  493.     exit()
  494. return
  495.